package Test1;

class Mylinklist {
    class Node {
        Node next;
        int data;

        public Node() {

        }

        public Node(int data) {
            this.data = data;
        }

    }

    private Node first;
    private Node current;
    public static int size;

    public void add(int val){

      Node n = new Node(val);

      if (first==null){
          first=n; //first = new node(1)
          current=n;//current = new node(1)
      }else{
          current.next=n;
          current=n; //current = new node(4)

      }
    size++;
    }

    public void addf(int d){
        Node e = new Node(d);

        if (first==null){
            first=e;
            current=e;
        }else{
            e.next=first;
            first=e;

        }
    size++;
    }

    public void print(){
        Node node=first;//first = new node(1) //current = new node(4)

        while (node!=null) {
            int value=node.data; //value =1
            System.out.println(value);
            node=node.next; //node.next =  new node(1)

        }
    }
    public Node insertFront(Node start, int x) {
        start = new Node();
        start.data = x;
        start.next = first;
        return start;
    }
   public void find(int value){
        Node no=first;
        int a =1;//index
        while(value!=no.data&&no.next!=null){
        a=a+1;
        no=no.next ;
   }
        if (value==no.data){
        System.out.println("the number of your find first is location in :"+a);
        }else{
            System.out.println("no number!");
        }

   }

   public void reverse(){
        Node p = first;
        current=first;
        first=null;
        Node q;
        while (p!=null){
            q=p.next;
            p.next=first;
            first=p;
            p=q;


        }

   }

   public int findMax(){
        Node find = first;
        int max=0;
         while(find!=null){
             if (find.data>max){
                 max=find.data;

             }
             find=find.next;
         }

   return max;
   }
    public int findMin(){
        Node find = first;
        int min=first.data;
        while(find!=null){
            if (find.data<min){
                min=find.data;

            }
            find=find.next;
        }

        return min;
    }
    public void inset(int index, int number) {
        if (index == 0) addf(number);
        else if (index >= size) add(number);
        else {
            Node current = first;
            for (int i = 1; i < index; i++)
                current = current.next;
            Node temp = current.next;
            current.next = new Node(number);
            (current.next).next = temp;
            size++;
        }
    }

    public void setSize() {
        System.out.println(size);
    }
}

public class ST{
    public static void main(String[] args ) {
        Mylinklist n=new Mylinklist();

//        for(int i=0;i<10000;i++){
//            n.add((int)(Math.random()*(100000 - 1 +1)));
//        }
//
//        System.out.println("the min :"+n.findMin());
//        n.setSize();
//        System.out.println("the max :"+n.findMax());

    }

}

